#把这个字符串的每个字符码点找出来，并生成一个列表来容纳
symbols = '$¢£¥€¤'
#方法1：垃圾方法
list1 = []
for i in symbols:
    list1.append(ord(i))
#方法2：列表推导式
list2 = [ord(i) for i in symbols]



colors = ['black', 'white']
sizes = ['S', 'M', 'L']
#使用列表计算笛卡尔积
list3 = [(color,size) for color in colors for size in sizes]
print(list3)
list4 = [(color,size) for size in sizes for color in colors ]
print(list4)
#注意list3和list4的排列顺序是不一致的


#生成器表达式
t1 = tuple(i for i in symbols)
t2 = (i for i in symbols)
print(f't1的类型是{type(t1)}')
print(f't1的类型是{type(t2)}')
t3 = ('%s %s'%(c,s) for c in colors for s in sizes)
print(f't3的类型是{type(t3)}')
print(t2)
for i in t2:
    print(i)


#元组的记录属性
city, year, pop, chg, area = ('Tokyo', 2003, 32450, 0.66, 8014)
traveler_ids = [('USA', '31195855'), ('BRA', 'CE342567'), ('ESP', 'XDA205856')]
for country,_ in traveler_ids:
    #_相当于占位符
    print(country)

str1 = 'ni'
str2 = 'wo'
str1,str2 = str2,str1 #不用中间变量交换


import os
dir = os.getcwd()
workpath,workfile = os.path.split(dir)#split返回的是一个元组
print(workfile)
print(workpath)

a, b, *rest = range(5)
print(type(rest))

metro_areas = [
('Tokyo','JP',36.933,(35.689722,139.691667)), ('Delhi NCR', 'IN', 21.935, (28.613889, 77.208889)), ('Mexico City', 'MX', 20.142, (19.433333, -99.133333)), ('New York-Newark', 'US', 20.104, (40.808611, -74.020386)), ('Sao Paulo', 'BR', 19.649, (-23.547778, -46.635833)),
]
for city,country,weizhi,(weidu,jingdu) in metro_areas:
    print(f'{city:<20}|{weidu:<10}|{jingdu:<10}')


#namedtuple
import collections
scored_ = collections.namedtuple('scored','chinese english')
a = scored_(100,99)
print(a)
print(f'中文成绩是:{a.chinese},英文成绩是：{a.english}')
print(type(a))